home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / hard / drivr / cnetdevice.lha / cnetdevice / src / include / cnet.i < prev    next >
Encoding:
Text File  |  1997-07-04  |  10.5 KB  |  251 lines

  1. ;----------------------------------------------------------------------------
  2. ;             Includes for CNET CN40-BC PCMCIA network card
  3. ;----------------------------------------------------------------------------
  4. ;           Original code by Bruce Abbott (bhabbott@inhb.co.nz)
  5. ;
  6. ;    "Some PC oriented eight (8) bit cards may require you read
  7. ;     odd-byte I/O address registers at the corresponding even-byte
  8. ;     address plus 64K.  There is sufficient I/O address space
  9. ;     provided that exceeding I/O address space should not be a problem."
  10. ;
  11. ;            (extract from Autodoc 'cardresource.doc')
  12. ;
  13. ; The following information applies to the CNet CN40BC. Other cards could
  14. ; be quite different.
  15. ;
  16. ; Even byte addresses start at $a20000, and are mirrored every 1K.
  17. ; Odd byte addresses start at $a30000. By positioning the base I/O address
  18. ; 1K below the start of odd addressing, we can access both even and odd
  19. ; I/O space using a single CPU Address Register (with 16 bit offsets).
  20. ;
  21.  
  22. IObase      = $10000-$0400+$0300      ; offset to even nic registers
  23. odd         = $10000-IOBase+$0300-1   ; offset to odd nic registers
  24.  
  25.  
  26. ;-----------------------------------------------------------------------
  27. ; The CNET CN40-BC uses a controller chip that is compatible with
  28. ; National Semiconducter's DS8390. This is the same chip that is
  29. ; used in NE1000 and NE2000 ISA bus ethernet cards.
  30.  
  31. ; --------------------- DS8390 registers ------------------------
  32. ; registers in bank 0
  33. nic_cr       =  0         ; command register        (r/w) in all banks
  34. nic_pstart   =  1+odd     ; page start               (w)
  35. nic_pstop    =  2         ; page stop                (w)
  36. nic_clda0    =  nic_pstop ; current local dma addr   (r)
  37. nic_bnry     =  3+odd     ; boundary pointer        (r/w)
  38. nic_clda1    =  nic_bnry  ; current local dma addr   (r)
  39. nic_tpsr     =  4         ; transmit page start      (w)
  40. nic_tsr      =  nic_tpsr  ; transmit status register (r)
  41. nic_tbcr0    =  5+odd     ; transmit byte count      (w)
  42. nic_ncr      =  nic_tbcr0 ; number of collisions     (r)
  43. nic_tbcr1    =  6         ; transmit byte count      (w)
  44. nic_fifo     =  nic_tbcr1 ; fifo contents            (r)
  45. nic_isr      =  7+odd     ; interrupt status        (r/w)
  46. nic_rsar0    =  8         ; remote start address     (w)
  47. nic_crda0    =  nic_rsar0 ; current remote DMA addr  (r)
  48. nic_rsar1    =  9+odd     ; remote start address     (w)
  49. nic_crda1    =  nic_rsar1 ; current remote DMA addr  (r)
  50. nic_rbcr0    = 10         ; remote byte count        (w)
  51. nic_rbcr1    = 11+odd     ; remote byte count        (w)
  52. nic_rcr      = 12         ; receive configuration    (w)
  53. nic_rsr      = nic_rcr    ; receive status           (r)
  54. nic_tcr      = 13+odd     ; transmit configuration   (w)
  55. nic_cntr0    = nic_tcr    ; tally counter            (r) frame align errors
  56. nic_dcr      = 14         ; data configuration       (w)
  57. nic_cntr1    = nic_dcr    ; tally counter            (r) crc errors
  58. nic_imr      = 15+odd     ; interrupt mask           (w)
  59. nic_cntr2    = nic_imr    ; tally counter            (r) missed packets
  60.  
  61. ; bank 1 and 2 registers
  62. nic_par0     =  1+odd  ; physical etheraddress   (r/w)
  63. nic_par1     =  2      ; physical etheraddress   (r/w)
  64. nic_par2     =  3+odd  ; physical etheraddress   (r/w)
  65. nic_par3     =  4      ; physical etheraddress   (r/w)
  66. nic_par4     =  5+odd  ; physical etheraddress   (r/w)
  67. nic_par5     =  6      ; physical etheraddress   (r/w)
  68. nic_curr     =  7+odd  ; current page            (r/w)
  69. nic_mar0     =  8      ; multicast etheraddress  (r/w)
  70. nic_mar1     =  9+odd  ; multicast etheraddress  (r/w)
  71. nic_mar2     = 10      ; multicast etheraddress  (r/w)
  72. nic_mar3     = 11+odd  ; multicast etheraddress  (r/w)
  73. nic_mar4     = 12      ; multicast etheraddress  (r/w)
  74. nic_mar5     = 13+odd  ; multicast etheraddress  (r/w)
  75. nic_mar6     = 14      ; multicast etheraddress  (r/w)
  76. nic_mar7     = 15+odd  ; multicast etheraddress  (r/w)
  77.  
  78. ; ASIC registers in the NE2000 card
  79. nic_data     = 16      ;  DMA port  (r/w)  16 bit
  80. nic_rst      = 31+odd  ;  card reset (r=reset, w=not)
  81.  
  82. ; DS8390 command bits
  83. DSCM_STOP    = $01 ; Stop controller
  84. DSCM_START   = $02 ; Start controller
  85. DSCM_TRANS   = $04 ; Transmit packet
  86. DSCM_RREAD   = $08 ; Remote read (read from nic memory to Amiga memory)
  87. DSCM_RWRITE  = $10 ; Remote write (write from Amiga memory to nic memory)
  88. DSCM_NODMA   = $20 ; No Remote DMA present
  89. DSCM_PG0     = $00 ; Select register bank 0
  90. DSCM_PG1     = $40 ; Select register bank 1
  91. DSCM_PG2     = $80 ; Select register bank 2
  92.  
  93. ; tansmit status register values
  94. DSTS_PTX     = $01 ; Successful packet transmit
  95. DSTS_COLL    = $02 ; Packet transmit w/ collision
  96. DSTS_COLL16  = $04 ; Packet had >16 collisions & fail
  97. DSTS_UND     = $20 ; FIFO Underrun on transmission
  98.  
  99. ; interrupt status register values
  100. DSIS_RX      = $01 ; Successful packet reception
  101. DSIS_TX      = $02 ; Successful packet transmission
  102. DSIS_RXE     = $04 ; Packet reception  w/error
  103. DSIS_TXE     = $08 ; Packet transmission  w/error
  104. DSIS_ROVRN   = $10 ; Receiver overrun in the ring
  105. DSIS_CTRS    = $20 ; Diagnostic counters need attn
  106. DSIS_RDC     = $40 ; Remote DMA Complete
  107. DSIS_RESET   = $80 ; Reset Complete
  108.  
  109. ; interrupt mask register values
  110. DSIM_PRXE    = $01 ; Packet received enable
  111. DSIM_PTXE    = $02 ; Packet transmitted enable
  112. DSIM_RXEE    = $04 ; Receive error enable
  113. DSIM_TXEE    = $08 ; Transmit error enable
  114. DSIM_OVWE    = $10 ; Overwrite warning enable
  115. DSIM_CNTE    = $20 ; Counter overflow enable
  116. DSIM_RDCE    = $40 ; Remote DMA complete enable
  117. DSIM_RESET   = $80 ; Reset Complete enable
  118.  
  119. ; Bit numbers for interrupts (same for int status and mask)
  120. DSIB_RX      = 0
  121. DSIB_TX      = 1
  122. DSIB_RXE     = 2
  123. DSIB_TXE     = 3
  124. DSIB_ROVRN   = 4
  125. DSIB_CTRS    = 5
  126. DSIB_RDC     = 6
  127. DSIB_RESET   = 7
  128.  
  129. INTMASK = $ff&~(DSIM_RESET|DSIM_RDCE) ; all ints except DMA, Reset complete
  130.  
  131.  
  132. ; data configuration register values
  133. DSDC_WTS     = $01 ; Word Transfer Select
  134. DSDC_BOS     = $02 ; Byte Order Select
  135. DSDC_LAS     = $04 ; Long Address Select
  136. DSDC_BMS     = $08 ; Burst Mode Select
  137. DSDC_AR      = $10 ; Autoinitialize Remote
  138. DSDC_FT0     = $20 ; Fifo Threshold Select
  139. DSDC_FT1     = $40 ; Fifo Threshold Select
  140.  
  141. ; receive status register values
  142. DSRS_RPC     = $01 ; Received Packet Complete
  143.  
  144. ; transmit configuration register values
  145. DSTC_CRC     = $01 ; Inhibit CRC
  146. DSTC_LB0     = $02 ; Encoded Loopback Control
  147. DSTC_LB1     = $04 ; Encoded Loopback Control
  148. DSTC_ATD     = $08 ; Auto Transmit Disable
  149. DSTC_OFST    = $10 ; Collision Offset Enable
  150.  
  151. ; receive configuration register values
  152. DSRC_SEP     = $01 ; Save error packets
  153. DSRC_AR      = $02 ; Accept Runt packets
  154. DSRC_AB      = $04 ; Accept Broadcast packets
  155. DSRC_AM      = $08 ; Accept Multicast packets
  156. DSRC_PRO     = $10 ; Promiscuous physical
  157. DSRC_MON     = $20 ; Monitor mode
  158.  
  159.  
  160. ;-------------------------------------------------------------------------
  161. ; Packet receive header, 1 per each buffer page used in receive packet.
  162. ; The nic inserts this in front of the received packet.
  163. ;
  164.  STRUCTURE prhdr,0
  165.    BYTE  prhdr_status  ; is this a good packet, same as ds0_rsr
  166.    BYTE  prhdr_nxtpg   ; next page of packet or next packet
  167.    BYTE  prhdr_sz0     ; length (lower byte)
  168.    BYTE  prhdr_sz1     ; length (upper byte)
  169.   LABEL  prhdr_sizeof
  170.  
  171. ;-------------------------------------------------------------------------
  172. ; nic has 16K of on-board RAM, from $4000 to $7fff (16 bit address)
  173. ;
  174. ; Internal DMA operations (ie. tx/rx) require the upper 8 bits of the
  175. ; address, as RAM is addressed in 256 byte pages.
  176. ;
  177. ; DMA to/from the host Amiga ("Remote DMA") requires a 16 bit word-aligned
  178. ; address
  179. ;
  180.  
  181. PKTSZ    =  $0600             ; space for biggest ethernet packet (6 pages)
  182.  
  183. TBUF     =  $4000             ; Starting location of Transmit Buffer
  184. TBUF1    =  $4000+PKTSZ       ; Another Tx Buffer (for double-buffered tx)
  185. RBUF     =  $4000+(PKTSZ*2)   ; Starting location of Receive Ring Buffer
  186. RBUFEND  =  $8000             ; Ending location of Receive Ring Buffer
  187.  
  188. ETHER_MIN_LEN = 64            ; smallest acceptable packet size
  189. ETHER_MAX_LEN = 1536          ; largest raw packet size
  190.  
  191. ; ethernet packet data sizes (maximum)
  192.  
  193. ETHERPKT_SIZE = 1500
  194. RAWPKT_SIZE   = 1514
  195.  
  196. ; size of our packet buffer
  197.  
  198. PKTBUF_SIZE   = 1600   ; actually only need 1536 ?
  199.  
  200. ; ethernet address bytesize
  201.  
  202. ETHER_ADDR_SIZE = 6
  203.  
  204. ; structure of an ethernet packet
  205.  
  206.   STRUCTURE etherpacket,0
  207.    STRUCT ether_dest,ETHER_ADDR_SIZE     ;  0 destination address
  208.    STRUCT ether_src,ETHER_ADDR_SIZE      ;  6 originator  address
  209.     WORD  ether_type                     ; 12 packet type
  210.    LABEL  ether_data                     ; 14 user data (up to 1500 bytes)
  211.  
  212.  
  213. ; our extension to device data
  214.  
  215.   STRUCTURE device_data,lib_size
  216.     BYTE  dd_flags                             ; various flags
  217.     BYTE  dd_dcr                               ; copy of nic data config reg
  218.     BYTE  dd_rcr                               ; copy of nic rx config reg
  219.     BYTE  dd_imr                               ; copy of nic intmask register
  220.     LONG  dd_overflows                         ; nic rx buffer overflow count
  221.     LONG  dd_errors                            ; bad packets received
  222.     LONG  dd_collisions                        ; tx collision count
  223.     LONG  dd_seglist                           ; device seglist
  224.     APTR  dd_copytobuf                         ; caller's read routine
  225.     APTR  dd_copyfrombuf                       ; caller's write routine
  226.     APTR  dd_cardres                           ; card.resource base
  227.     APTR  dd_cmm                               ; card memory map
  228.    STRUCT dd_romstationaddress,ETHER_ADDR_SIZE ; hardware address from ROM
  229.    STRUCT dd_stationaddress,ETHER_ADDR_SIZE    ; hardware station addr used
  230.    STRUCT dd_readlist,mlh_size                 ; read requests
  231.    STRUCT dd_writelist,mlh_size                ; write requests
  232.    STRUCT dd_eventlist,mlh_size                ; events
  233.    STRUCT dd_cardhandle,cah_sizeof             ; credit card handle
  234.    STRUCT dd_cardstatus,is_size                ; card status interrupt
  235.    STRUCT dd_cardremoved,is_size               ; card removed interrupt
  236.    STRUCT dd_cardinserted,is_size              ; card inserted interrupt
  237.    STRUCT dd_txint,is_size                     ; transmit software interrupt
  238.    STRUCT dd_rxint,is_size                     ; receive software interrupt
  239.     LABEL dd_extsize
  240.  
  241.  
  242. ; bit definitions for dd_flags
  243.  
  244.  BITDEF DD,CARDIN,1         ; card is inserted
  245.  BITDEF DD,NICUP,2          ; controller hardware is initialised
  246.  BITDEF DD,OWNED,3          ; owncard was successful
  247.  BITDEF DD,CONFIGURED,4     ; hardware address is configured
  248.  BITDEF DD,ONLINE,5         ; device is online
  249.  BITDEF DD,TX,6             ; transmit buffer is full
  250.  BITDEF DD,DEVINIT,7        ; device is initialised
  251.